package me.zhengjie.modules.finace_taxation.rest;

import me.zhengjie.annotation.Log;
import me.zhengjie.modules.finace_taxation.domain.FtFeedback;
import me.zhengjie.modules.finace_taxation.service.FtFeedbackService;
import me.zhengjie.modules.finace_taxation.service.dto.FtFeedbackDto;
import me.zhengjie.modules.finace_taxation.service.dto.FtFeedbackQueryParam;
import org.springframework.data.domain.Pageable;
import lombok.RequiredArgsConstructor;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import io.swagger.annotations.*;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.Set;

/**
* @author 杨荣森
* @date 2021-06-23
**/
@RestController
@RequiredArgsConstructor
@Api(tags = "feedback管理")
@RequestMapping("/api/ft/ftFeedback")
public class FtFeedbackController {

    private final FtFeedbackService ftFeedbackService;

    @GetMapping
    @Log("查询意见反馈")
    @ApiOperation("查询意见反馈")
//    @PreAuthorize("@el.check('ftFeedback:list')")
    public ResponseEntity query(FtFeedbackQueryParam query, Pageable pageable){
        return new ResponseEntity<>(ftFeedbackService.queryAll(query,pageable),HttpStatus.OK);
    }

    @PostMapping
    @Log("新增意见反馈")
    @ApiOperation("新增意见反馈")
//    @PreAuthorize("@el.check('ftFeedback:add')")
    public ResponseEntity create(@Validated @RequestBody FtFeedbackDto resources){
        resources.setId("");
        return new ResponseEntity<>(ftFeedbackService.insert(resources),HttpStatus.CREATED);
    }

    @PutMapping
    @Log("修改意见反馈")
    @ApiOperation("修改意见反馈")
//    @PreAuthorize("@el.check('ftFeedback:edit')")
    public ResponseEntity update(@Validated @RequestBody FtFeedbackDto resources){
        ftFeedbackService.updateById(resources);
        return new ResponseEntity<>(HttpStatus.NO_CONTENT);
    }

    @DeleteMapping
    @Log("删除意见反馈")
    @ApiOperation("删除意见反馈")
//    @PreAuthorize("@el.check('ftFeedback:del')")
    public ResponseEntity delete(@RequestBody Set<String> ids) {
        ftFeedbackService.removeByIds(ids);
        return new ResponseEntity<>(HttpStatus.OK);
    }

    @Log("导出意见反馈")
    @ApiOperation("导出意见反馈")
    @GetMapping(value = "/download")
    public void download(HttpServletResponse response, FtFeedbackQueryParam query) throws IOException {
        ftFeedbackService.download(ftFeedbackService.queryAll(query), response);
    }

}
